import platform
def install():
    '''
    将yum的源设置成中科大源，
    参考：https://lug.ustc.edu.cn/wiki/mirrors/help/centos
    '''
    if platform.system()=='Linux':
        linux_distribution = platform.linux_distribution(full_distribution_name=0)
        os_name = linux_distribution[0].lower()
        if os_name == 'centos':
            get_os_big_version = lambda v:v[:v.find('.')] if v.find('.') >=0 else v
            os_version = linux_distribution[1]
            os_big_version = get_os_big_version(os_version)
            import os
            os.system("sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup")
            os.system("sudo cp ./centos{}/CentOS-Base.repo /etc/yum.repos.d/".format(os_big_version))
            os.system("sudo yum makecache")
            print("yum源成功设置为中科大镜像源！")
            return True
        else:
            print("本yum源设置目前仅支持CentOS Linux系统")
    else:
        print("本yum源设置目前仅支持CentOS Linux系统")

install()
